<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content=
    "application/xhtml+xml; charset=iso-8859-1" />
    <title>
      6.2.&nbsp;Preparing Virtual Kernel File Systems
    </title>
    <link rel="stylesheet" type="text/css" href="../stylesheets/lfs.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="stylesheet" href="../stylesheets/lfs-print.css" type=
    "text/css" media="print" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body class="lfs" id="lfs-8.0-systemd">
    <div class="navheader">
      <h4>
        Linux From Scratch - Version 8.0-systemd
      </h4>
      <h3>
        Chapter&nbsp;6.&nbsp;Installing Basic System Software
      </h3>
      <ul>
        <li class="prev">
          <a accesskey="p" href="introduction.html" title=
          "Introduction">Prev</a>
          <p>
            Introduction
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="pkgmgt.html" title=
          "Package Management">Next</a>
          <p>
            Package Management
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter06.html" title=
          "Chapter&nbsp;6.&nbsp;Installing Basic System Software">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Linux From Scratch - Version 8.0-systemd">Home</a>
        </li>
      </ul>
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <h1 class="sect1">
        <a id="ch-system-kernfs" name="ch-system-kernfs"></a>6.2. Preparing
        Virtual Kernel File Systems
      </h1>
      <p>
        Various file systems exported by the kernel are used to communicate
        to and from the kernel itself. These file systems are virtual in that
        no disk space is used for them. The content of the file systems
        resides in memory.
      </p>
      <p>
        Begin by creating directories onto which the file systems will be
        mounted:
      </p>
      <pre class="userinput">
<kbd class="command">mkdir -pv $LFS/{dev,proc,sys,run}</kbd>
</pre>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          6.2.1. Creating Initial Device Nodes
        </h2>
        <p>
          When the kernel boots the system, it requires the presence of a few
          device nodes, in particular the <code class=
          "filename">console</code> and <code class="filename">null</code>
          devices. The device nodes must be created on the hard disk so that
          they are available before <span class=
          "command"><strong>udevd</strong></span> has been started, and
          additionally when Linux is started with <em class=
          "parameter"><code>init=/bin/bash</code></em>. Create the devices by
          running the following commands:
        </p>
        <pre class="userinput">
<kbd class="command">mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3</kbd>
</pre>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          <a id="ch-system-bindmount" name="ch-system-bindmount"></a>6.2.2.
          Mounting and Populating /dev
        </h2>
        <p>
          The recommended method of populating the <code class=
          "filename">/dev</code> directory with devices is to mount a virtual
          filesystem (such as <code class="systemitem">tmpfs</code>) on the
          <code class="filename">/dev</code> directory, and allow the devices
          to be created dynamically on that virtual filesystem as they are
          detected or accessed. Device creation is generally done during the
          boot process by Udev. Since this new system does not yet have Udev
          and has not yet been booted, it is necessary to mount and populate
          <code class="filename">/dev</code> manually. This is accomplished
          by bind mounting the host system's <code class=
          "filename">/dev</code> directory. A bind mount is a special type of
          mount that allows you to create a mirror of a directory or mount
          point to some other location. Use the following command to achieve
          this:
        </p>
        <pre class="userinput">
<kbd class="command">mount -v --bind /dev $LFS/dev</kbd>
</pre>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          <a id="ch-system-kernfsmount" name=
          "ch-system-kernfsmount"></a>6.2.3. Mounting Virtual Kernel File
          Systems
        </h2>
        <p>
          Now mount the remaining virtual kernel filesystems:
        </p>
        <pre class="userinput">
<kbd class="command">mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run</kbd>
</pre>
        <div class="variablelist">
          <p class="title">
            <strong>The meaning of the mount options for devpts:</strong>
          </p>
          <dl class="variablelist">
            <dt>
              <span class="term"><em class=
              "parameter"><code>gid=5</code></em></span>
            </dt>
            <dd>
              <p>
                This ensures that all devpts-created device nodes are owned
                by group ID 5. This is the ID we will use later on for the
                <code class="systemitem">tty</code> group. We use the group
                ID instead of a name, since the host system might use a
                different ID for its <code class="systemitem">tty</code>
                group.
              </p>
            </dd>
            <dt>
              <span class="term"><em class=
              "parameter"><code>mode=0620</code></em></span>
            </dt>
            <dd>
              <p>
                This ensures that all devpts-created device nodes have mode
                0620 (user readable and writable, group writable). Together
                with the option above, this ensures that devpts will create
                device nodes that meet the requirements of grantpt(), meaning
                the Glibc <span class=
                "command"><strong>pt_chown</strong></span> helper binary
                (which is not installed by default) is not necessary.
              </p>
            </dd>
          </dl>
        </div>
        <p>
          In some host systems, <code class="filename">/dev/shm</code> is a
          symbolic link to <code class="filename">/run/shm</code>. The /run
          tmpfs was mounted above so in this case only a directory needs to
          be created.
        </p>
        <pre class="userinput">
<kbd class="command">if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi</kbd>
</pre>
      </div>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="introduction.html" title=
          "Introduction">Prev</a>
          <p>
            Introduction
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="pkgmgt.html" title=
          "Package Management">Next</a>
          <p>
            Package Management
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter06.html" title=
          "Chapter&nbsp;6.&nbsp;Installing Basic System Software">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Linux From Scratch - Version 8.0-systemd">Home</a>
        </li>
      </ul>
    </div>
  </body>
</html>
